#!/bin/sh
CRONTAB=/var/etc/crontab
c=10

hexdec()
{
  hex=$1
  pos=1
  dec=0
  while [ "${hex#0}" != "$hex" ]
  do
    hex="${hex#0}"
  done
  while [ "$hex" != "" ]
  do
    nhex=${hex%?}
    nibble=$(eval echo ${hex#$nhex})
    hex="$nhex"
    [ "${nibble#a}" = "" ] && nibble=10
    [ "${nibble#b}" = "" ] && nibble=11
    [ "${nibble#c}" = "" ] && nibble=12
    [ "${nibble#d}" = "" ] && nibble=13
    [ "${nibble#e}" = "" ] && nibble=14
    [ "${nibble#f}" = "" ] && nibble=15
    dec=$((dec+nibble*pos))            
    pos=$((pos*16))                    
  done                                 
  echo $dec                            
}                                      

while [ $c -gt 0 ]
do
  remain=$(date +%S|sed 's/^0//')
  sleep $((60-remain))
  set $(date '+%M %H %d %m %w')
  cat "$CRONTAB"|
  while read minute hour day month wday command
  do
    echo "$minute $hour $day $month $wday $command"
    runit=""
    if [ "${minute###}" != "$minute" ]    # it's a comment
    then
      continue
    fi 
    [ "$minute" = "$1" ] || [ "$minute" = "*" ] && runit=$runit"M"
    [ "$hour" = "$2" ] || [ "$hour" = "*" ] && runit=$runit"H"
    [ "$day" = "$3" ] || [ "$day" = "*" ] && runit=$runit"d"
    [ "$month" = "$4" ] || [ "$month" = "*" ] && runit=$runit"m"
    [ "$wday" = "$5" ] || [ "$wday" = "*" ] && runit=$runit"w"
    if [ "$runit" = "MHdmw" ]
    then
      log="/tmp/log-$(date +%Y%m%d)"
      echo "$(date) running $command" >> $log
      $command >>$log 2>&1 &
    fi 
  done 
done 
